/**
 * Created by asus on 2016/11/25.
 */

import * as URL from './url'

import {apiGet,apiPost} from './rpc';

export const version = '1.0.0'
export const client = 'wx'

//设置imei
const createUUID = function () {
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }

    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
};

let cookieImei = localStorage.getItem('imei');

if (!cookieImei) {
    var expiresDate = new Date();
    expiresDate.setTime(expiresDate.getTime() + (43200 * 60 * 1000));
    localStorage.setItem('imei', createUUID());
    cookieImei = localStorage.getItem('imei');
}

export const imei = cookieImei


/***********************************************/

//获取短信验证码
export async function SMSCode(mobile,role){
    try{
        const res = await apiGet(URL.smsCode,{mobile,role});
        return res;
    }catch (err){
        console.warn('SMSCode',err);
        throw err
    }
}

//忘记密码
export async function UpdateLoginPwd(mobile,pwd,smsNo,code,role){
    try{
        const res = await apiPost(URL.updateLoginPwd,{mobile,pwd,smsNo,code,role});
        return res;
    }catch (err){
        console.warn('toRegister',err);
        throw err
    }
}

//查看个人资料
export async function MyInfo(){
    try{
        const res = await apiGet(URL.myInfo);
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//微信授权
export function WxLogin(code){
    try{
        const res = apiGet(URL.wxLogin,{code});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//支付发起接口
export async function ToBcPay(tranType,bizParam){
    try{
        const res = await apiGet(URL.bc,{tranType,bizParam});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//商品列表
export async function ProductList(status,page,name ='',type=0,order = '',orderName ='',minPrice ='',maxPrice ='') {
    try {
        const res = await apiPost(URL.productList,{status,page,name,type,order,orderName,minPrice,maxPrice});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//商品列表
export async function AgentProductList(status,page,name ='',type=0,order = '',orderName ='',minPrice ='',maxPrice ='') {
    try {
        const res = await apiPost(URL.agentProductList,{status,page,name,type,order,orderName,minPrice,maxPrice});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//商品详情
export async function Details(productId) {
    try {
        const res = await apiGet(URL.detail, {productId});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//商品评价列表
export async function RemarkList(productId,page,orderNo){
    try{
        const res = await apiGet(URL.remarkList,{productId,page,orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//商品属性
export async function ProductAttribute(productId){
    try{
        const res = await apiGet(URL.productAttribute,{productId});
        return res;
    }catch (err){
        console.warn('ProductAttribute',err);
        throw err
    }
}
//登陆
/*export async function ToLogin(){
    if(!loadToken('token')){
        try{
            const res = await apiPost(URL.login);
            saveToken(GetQueryString('token'))
            return res;
        }catch (err){
            // console.warn('toRegister',err);
            throw err
        }
    }

}*/

//商品列表
/*export async function ProductList(name ='',order = '',orderName ='',minPrice ='',maxPrice ='') {
    try {
        const res = await apiPost(URL.productList,{name,order,orderName,minPrice,maxPrice});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}*/

//加入购物车
export async function AddShopCar(productId,attrIds = '',count) {
    try {
        const res = await apiGet(URL.addShopCar, {productId, attrIds, count});
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//立即购买
export async function OrderShopping(productId,attrIds,num,isShareOrder = 0,agentId = 0){
    try{
        const res = await apiGet(URL.orderShopping,{productId,attrIds,num,isShareOrder,agentId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//根据订单号查询订单
export async function ListByOrderNo(orderNos){
    try{
        const res = await apiGet(URL.listByOrderNo,{orderNos});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//设置收货地址
export async function SetAddress(orderNos,addressId){
    try{
        const res = await apiGet(URL.setAddress,{orderNos,addressId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//购物车列表
export async function ShopCarList(page){
    try{
        const res = await apiGet(URL.shopCarList,{page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//更新购物车数量
export async function EditShopNum(carId,count){
    try{
        const res = await apiGet(URL.editShopNum,{carId,count});

        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//删除购物车
export async function DelShopCar(carIds){
    try{
        const res = await apiGet(URL.delShopCar,{carIds});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//购物车结算
export async function SettlementShopCar(carIds,agentId){
    try{
        const res = await apiGet(URL.settlementShopCar,{carIds,agentId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//进货结算
export async function SettlementPurchase(jsonParam){
    try{
        const res = await apiGet(URL.settlementPurchase,{jsonParam});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//库存列表
export async function StockList(page){
    try{
        const res = await apiGet(URL.stockList,{page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//库存取货
export async function AddWarehouseOrder(jsonParam,addressId,isPostage){//isPostage  :'上级包邮''下级自付'
    try{
        const res = await apiGet(URL.addWarehouseOrder,{jsonParam,addressId,isPostage});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//授权资料
export async function authInfo(recommendId){
    try{
        const res = await apiGet(URL.authInfo,{recommendId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//订单列表
export async function GetOrderList(status,isComment,type=0,page){
    try{
        const res = await apiGet(URL.orderList,{status,isComment,type,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//授权资料
export async function getLeaderInfo(recommendId,grade){
    try{
        const res = await apiGet(URL.getLeaderInfo,{recommendId,grade});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//订单详情
export async function OrderDetail(orderNo){
    try{
        const res = await apiGet(URL.orderDetail,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//授权申请
export async function authApply(recommendId,accIdImg,name,mobile,province,city,area){
    try{
        const res = await apiGet(URL.authApply,{recommendId,accIdImg,name,mobile,province,city,area});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//授权申请
export async function authApply2(recommendId,accIdImg,payImg,judgeAccId,judgeAccName,name,mobile,wxAccName,agentId){
    try{
        const res = await apiGet(URL.authApply2,{recommendId,accIdImg,payImg,judgeAccId,judgeAccName,name,mobile,wxAccName,agentId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//获取授权列表
export async function agentApplyList(status,page){
    try{
        const res = await apiGet(URL.agentApplyList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//审核授权
export async function review(status,id){
    try{
        const res = await apiGet(URL.review,{status,id});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//待处理订单列表
export async function GetSellerOrderList(status) {
    try {
        const res = await apiGet(URL.sellerList, {status});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//去发货
/*
export async function Delivery(deliveryName,deliveryNo,orderNo) {
    try {
        const res = await apiPost(URL.delivery,{deliveryName,deliveryNo,orderNo});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}
*/

//取消订单
export async function CancelReceived(orderNo){
    try{
        const res = await apiGet(URL.cancelReceive,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//新增地址
export async function AddAddress(name,mobile,address,detail,province,city,area){
    try{
        const res = await apiPost(URL.addAddress,{name,mobile,address,detail,province,city,area});
        return res;
    }catch (err){
        console.warn('AddAddress',err);
        throw err
    }
}

//编辑地址
export async function EditAddress(name,mobile,address,detail,addressId,province,city,area){
    try{
        const res = await apiPost(URL.editAddress,{name,mobile,address,detail,addressId,province,city,area});
        return res;
    }catch (err){
        console.warn('EditAddress',err);
        throw err
    }
}

//地址列表
export async function AddressList(){
    try{
        const res = await apiGet(URL.addressList);
        return res;
    }catch (err){
        console.warn('AddressList',err);
        throw err
    }
}

//删除地址
export async function DelAddress(addressId) {
    try {
        const res = await apiGet(URL.delAddress,{addressId});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//设置默认地址
export async function DefaultAddress(addressId){
    try{
        const res = await apiGet(URL.defaultAddress,{addressId});
        return res;
    }catch (err){
        console.warn('DefaultAddress',err);
        throw err
    }
}

//查看默认地址
export async function QueryDefault(){
    try{
        const res = await apiGet(URL.queryDefault);
        return res;
    }catch (err){
        console.warn('DefaultAddress',err);
        throw err
    }
}

//确认删除订单
export async function ConfirmCancel(orderNo){
    try{
        const res = await apiGet(URL.confirmCancel,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//确认收货
export async function ConfirmReceived(orderNo) {
    try {
        const res = await apiGet(URL.confirmReceive, {orderNo});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

export async function TeamInfoList(page) {
    try {
        const res = await apiGet(URL.teamInfoList, {page});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//rechargeApply
export async function RechargeApply(chargeImg,amount) {
    try {
        const res = await apiGet(URL.rechargeApply, {chargeImg,amount});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}


//代理结构图
export async function StatisInfo() {
    try {
        const res = await apiGet(URL.statisInfo);
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}
//审核授权
export async function Rechargereview(status,id){
    try{
        const res = await apiGet(URL.rechargereview,{status,id});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//下级代理
export async function NextStatisInfo(id) {
    try {
        const res = await apiGet(URL.nextStatisInfo,{id});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//审核充值列表
export async function RechargeList(status,page){
    try{
        const res = await apiGet(URL.rechargeList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//审核充值列表
export async function QueryPayResult(bizParam){
    try{
        const res = await apiGet(URL.queryPayResult,{bizParam});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//成为代理首次进货
export async function ProductPropertyCheck(agentId){
    try{
        const res = await apiGet(URL.productPropertyCheck,{agentId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//升级代理
export async function JudgeUp(agentId){
    try{
        const res = await apiGet(URL.judgeUp,{agentId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//商品评价
export async function Remark(orderNo,productId,comment,images) {
    try {
        const res = await apiPost(URL.remark, {orderNo, productId, comment, images});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//发货列表
export async function LeaderDeliveryOrderList(status,page){
    try{
        const res = await apiGet(URL.leaderDeliveryOrderList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//进货列表
export async function DeliveryOrderList(status,page){
    try{
        const res = await apiGet(URL.deliveryOrderList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//去发货
export async function Delivery(orderNo){
    try{
        const res = await apiGet(URL.delivery,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//配货订单列表
export async function WarehouseList(status,page){
    try{
        const res = await apiGet(URL.warehouseList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//配货订单列表
export async function LeaderWarehouseList(status,page){
    try{
        const res = await apiGet(URL.leaderWarehouseList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//余额交易记录
export async function AmountInfo(page){
    try{
        const res = await apiGet(URL.amountInfo,{page});

        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//我的推荐
export async function RecommendList(page){
    try{
        const res = await apiGet(URL.recommendList,{page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//余额交易记录
export async function UserAmountInfo(page){
    try{
        const res = await apiGet(URL.userAmountInfo,{page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//我的推荐
export async function BannerList(type,page,count){
    try{
        const res = await apiGet(URL.bannerList,{type,page,count});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//确认提现
export async function Cash(bankcardId,amount) {
    try {
        const res = await apiGet(URL.cash,{bankcardId,amount});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//银行卡列表
export async function BankList(){
    try{
        const res = await apiGet(URL.bankList);
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//判断是否填写授权资料
export async function ApplyCheck(){
    try{
        const res = await apiGet(URL.applyCheck);
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//绑定银行卡
export async function BandBank(bankName,name,bankCardNo,pro,city,area,branch,mobile,idNo){
    try{
        const res = await apiGet(URL.bindBank,{bankName,name,bankCardNo,pro,city,area,branch,mobile,idNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}


//编辑银行卡信息
export async function BankUpdate(bankId,bankName,name,bankCardNo,pro,city,area,branch,mobile,idNo) {
    try {
        const res = await apiGet(URL.bankUpdate,{bankId,bankName,name,bankCardNo,pro,city,area,branch,mobile,idNo});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//删除银行卡
export async function UnBinding(bankId) {
    try {
        const res = await apiGet(URL.unBinding,{bankId});
        return res;
    } catch (err) {
        console.warn(err);
        throw err
    }
}

//删除订单
export async function OrderDel(orderNo){
    try{
        const res = await apiGet(URL.orderDel,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

/*//我的配货订单
export async function LeaderWarehouseList(status,page){
    try{
        const res = await apiGet(URL.leaderWarehouseList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}*/

//我的配货订单
export async function deliveryByLeader(deliveryName,deliveryNo,orderNo){
    try{
        const res = await apiGet(URL.deliveryByLeader,{deliveryName,deliveryNo,orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//我的配货订单(为普通用户发货)
export async function DeliveryBuyer(deliveryName,deliveryNo,orderNo){
    try{
        const res = await apiGet(URL.deliveryBuyer,{deliveryName,deliveryNo,orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//代理与普通用户的订单列表
export async function SellerList(status,page,storeId){
    try{
        const res = await apiGet(URL.sellerList,{status,page,storeId});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//大额支付-获取验证码
export async function BcAuthPrepare(tranType,bizParam){
    try{
        const res = await apiGet(URL.bcAuthPrepare,{tranType,bizParam});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//大额支付确定
export async function BcAuthPay(channelOrderNo,smsNo){
    try{
        const res = await apiGet(URL.bcAuthPay,{channelOrderNo,smsNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//大额支付确定
export async function UpGrade(){
    try{
        const res = await apiGet(URL.upgrade);
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//虚仓退换货
export async function VirtualReturnApply(changeJsonPram,returnJsonPram){
    try{
        const res = await apiGet(URL.virtualReturnApply,{changeJsonPram,returnJsonPram});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//实仓退换货
export async function WarehouseReturnApply(changeJsonPram,returnJsonPram,deliveryNo){
    try{
        const res = await apiGet(URL.warehouseReturnApply,{changeJsonPram,returnJsonPram,deliveryNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//退换货审批列表
export async function ReturnList(status,page){
    try{
        const res = await apiGet(URL.returnList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//退换货审批详情
export async function ReturnListDetail(orderNo){
    try{
        const res = await apiGet(URL.returnListDetail,{orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//同意审批
export async function ReturnOrderDelivery(orderNo,status){
    try{
        const res = await apiGet(URL.returnOrderDelivery,{orderNo,status});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//升级状态
export async function UpgradeCheck(){
    try{
        const res = await apiGet(URL.upgradeCheck);
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//我的退换货订单
export async function MyReturnList(status,page){
    try{
        const res = await apiGet(URL.myReturnList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//绑定手机号
export async function BindingAccName(smsNo,accName,pwd){
    try{
        const res = await apiGet(URL.bindingAccName,{smsNo,accName,pwd});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//获取断线验证码
export async function Binding(accName){
    try{
        const res = await apiGet(URL.binding,{accName});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//查询支付凭证
export async function PayOrderList(status,type,page){
    try{
        const res = await apiGet(URL.payOrderList,{status,type,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//审核支付凭证
export async function AuditPayOrder(status,orderNo){
    try{
        const res = await apiGet(URL.auditPayOrder,{status,orderNo});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//上传支付凭证
export async function AddPayOrder(no,noType='',image,amount,type,extraMsg1 = ''){
    try{
        const res = await apiGet(URL.addPayOrder,{no,noType,image,amount,type,extraMsg1});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//充值生成订单
export async function SaveRechargeOrder(bizParam,tranType){
    try{
        const res = await apiGet(URL.saveRechargeOrder,{bizParam,tranType});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//我的凭证
export async function CredentialList(status,page){
    try{
        const res = await apiGet(URL.credentialList,{status,page});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//注册
export async function ToRegister(accName,pwd,smsNo,code){
    try{
        const res = await apiPost(URL.add,{accName,pwd,smsNo,code});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//获取短信验证码
export async function ToReg(mobile){
    try{
        const res = await apiGet(URL.reg,{mobile});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}

//登录
export async function ToLogin(accName,pwd){
    try{
        const res = await apiGet(URL.login,{accName,pwd});
        return res;
    }catch (err){
        console.warn(err);
        throw err
    }
}